<html>
<head>
<title>[Fltk-2.x] NativeFileChooser</title>
</head>
<body>
<H1>[Fltk-2.x] NativeFileChooser</H1>

<h2>class fltk::NativeFileChooser</a></h2>
<!--
<h3>Class Hierarchy</h3>
<ul>
  <pre>
  NativeFileChooser
  </pre>
</ul>
-->

<h3>Include Files</h3>
<ul>
  <pre>
  #include &lt;fltk/NativeFileChooser.h&gt;
  </pre>
</ul>
Dowload latest source from <a href="http://seriss.com/people/erco/fltk/Fl_NativeFileChooser/">here</a>.
<br>
<h3>Description</h3>
This class lets an FLTK2 application easily and consistently access
the local operating system's native file chooser. Some operating systems
have very complex and specific file choosers that many users want access
to specifically, instead of FLTK2's default file chooser(s).
<p>
<h3>Methods</h3>
<center>
<table width="90%" summary="fltk::NativeFileChooser methods">
<tr><td align="left" valign="top">
<ul>
  <li> <a href="#NativeFileChooser">NativeFileChooser</a>
  <li> <a href="#~NativeFileChooser">~NativeFileChooser</a>
  <li> <a href="#count">count</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#directory">directory</a>
  <li> <a href="#errmsg">errmsg</a>
  <li> <a href="#filename">filename</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#filter">filter</a>
  <li> <a href="#filter_value">filter_value</a>
  <li> <a href="#filters">filters</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#options">options</a>
  <li> <a href="#preset_file">preset_file</a>
  <li> <a href="#show">show</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#title">title</a>
  <li> <a href="#type">type</a>
</ul>
&nbsp;<br>
&nbsp;<br>
</td> </tr> </table>
</center>

<h4><a name="NativeFileChooser">
fltk::NativeFileChooser::NativeFileChooser()<br>
fltk::NativeFileChooser::NativeFileChooser(type)
</h4>
<ul>
    The constructor for the fltk::NativeFileChooser.
    <p>
    If the optional <tt>type</tt> is not specified,
    BROWSE_FILE (browse to open a file) is assumed.  
    The type can also be set later with <a href="#type">type()</a>.
</ul>

<h4><a name="~NativeFileChooser">
fltk::NativeFileChooser::~NativeFileChooser()
</h4>
<ul>
    The destructor; destroys any resources allocated to this widget.
</ul>

<h4>
<a name="count"></a>
int fltk::NativeFileChooser::count() const
</h4>
<ul>
    Returns the number of filenames (or directory names) the user
    selected. These are zero-indexed. 
    See this example of <a href="#multi_example">how to retrieve
    multiple filenames</a>.
</ul>


<h4>
<a name="directory"></a>
void fltk::NativeFileChooser::directory(const char*)<br>
const char* fltk::NativeFileChooser::directory() const;<br>
</h4>
<ul>
    Sets the directory with which to start the chooser.
    If NULL is passed, or if no directory is specified,
    the chooser will attempt to use the last non-cancelled folder.<br>
</ul>

<h4>
<a name="errmsg"></a>
const char *fltk::NativeFileChooser::errmsg() const<br>
</h4>
<ul>
    Returns a system dependent error message for the last
    method that failed. This message should at least be flagged
    to the user in a dialog box, or to some kind of error log.
</ul>

<h4>
<a name="filename"></a>
const char *fltk::NativeFileChooser::filename() const<br>
const char *fltk::NativeFileChooser::filename(int) const<br>
</h4>
<ul>
    The first form returns the single filename selected
    by the user from the browser. (In a multiple browser
    context, this returns the first filename the user selected).
    <p>
    The second form should be used to return multiple filenames,
    and is normally used inside a loop to retrieve all the files
    the user selected, eg:
    <p>
    <a name="multi_example">
    <pre>
        if ( <b>chooser->show()</b> == 0 ) {
            // HANDLE MULTIPLE FILENAMES
            for (int n = 0; n &lt; <b>chooser->count()</b>; n++ ) {
      	        fprintf(stderr, "%d) '%s'\n", n, <b>chooser->filename(n)</b>);
            }
	}
    </pre>
    You can preset the directory with 
    <a href="#directory">directory()</a> method, and the filename using the
    <a href="#preset_file">preset_file()</a> method.<br>
</ul>

<h4>
<a name="filter"></a>
const char *fltk::NativeFileChooser::filter() const<br>
void fltk::NativeFileChooser::filter(const char*)
</h4>
<ul>
    Gets or sets the filename filters used for browsing.
    The default is NULL, which browses all files.
    <p>
    The filter string can be any of:
    <p>
    <ul>
        <li> A single wildcard (eg. "*.txt")
	     </li>
	<li> Multiple wildcards (eg. "*.{cxx,h,H})
	     </li>
	<li> A descriptive name followed by a '\t' and a wildcard
	     (eg. "Text&nbsp;Files\t*.txt")
	     </li>
	<li> A list of separate wildcards with a \n between each (eg. "*.{cxx,H}\n*.txt")
	     </li>
	<li> A list of descriptive names and wildcards 
	     (eg. "C++ Files\t*.{cxx,H}\nTxt Files\t*.txt")
	     </li>
    </ul>
    <p>
    The format of each filter is a wildcard, or an optional
    user description followed by '\t' and the wildcard.
    <p>
    On most platforms, each filter is available to the user
    via a pulldown menu in the file chooser. The 'All Files'
    option is always available to the user.
</ul>

<h4>
<a name="filter_value"></a>
void fltk::NativeFileChooser::filter_value(int)<br>
int fltk::NativeFileChooser::filter_value()<br>
</h4>
<ul>
    The first form sets which filter will be initially selected.<br>
    The second returns which filter was chosen. This is only valid
    if the chooser returns success.<br>
    <p>
    The first filter is indexed as 0. If filter_value()==filters(),
    then "All Files" was chosen. If filter_value() > filters(), then
    a custom filter was set.<br>
</ul>

<h4>
<a name="filters"></a>
int fltk::NativeFileChooser::filters()<br>
</h4>
<ul>
    Gets how many filters were available, not including "All Files"
</ul>

<h4>
<a name="options"></a>
void fltk::NativeFileChooser::options(int)<br>
int fltk::NativeFileChooser::options()<br>
</h4>
<ul>
    Sets/gets the platform specific chooser options.
    <p>
    Some platforms have file choosers with specific functions
    that can be enabled/disabled via this method.
    <p>
    Flags can be ORed together to enable several features. Flags currently supported:
    <p>
    <center><table cellpadding=3>
        <tr><td BGCOLOR=#8888cc align=left>Flag          </td><td BGCOLOR=#8888cc>Description                                                        </td><td BGCOLOR=#8888cc>Win</td><td BGCOLOR=#8888cc>Mac</td><td BGCOLOR=#8888cc>Other</td></tr>
        <tr><td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::SAVEAS_CONFIRM</td><td BGCOLOR=#dddddd>With a BROWSE_SAVEAS chooser, prompts a confirmation if file exists</td><td BGCOLOR=#dddddd>Ignored </td><td BGCOLOR=#88dd88>Used   </td><td BGCOLOR=#dddddd>Ignored</td></tr>
        <tr><td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::NEW_FOLDER    </td><td BGCOLOR=#dddddd>Shows the 'New Folder' button                                      </td><td BGCOLOR=#dddddd>Ignored </td><td BGCOLOR=#dddddd>Ignored</td><td BGCOLOR=#88dd88>Used</td></tr>
        <tr><td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::PREVIEW       </td><td BGCOLOR=#dddddd>Enables the 'Preview' mode by default                              </td><td BGCOLOR=#dddddd>Ignored </td><td BGCOLOR=#dddddd>Ignored</td><td BGCOLOR=#88dd88>Used</td></tr>
    </table></center>
</ul>

<h4>
<a name="preset_file"></a>
void fltk::NativeFileChooser::preset_file(const char*)<br>
const char* fltk::NativeFileChooser::preset_file()<br>
</h4>
<ul>
    Sets a default filename for the chooser. 
    (Use <a href="#directory">directory()</a> to set the default directory)
    <br>
    Mainly used to preset the filename for save dialogs, 
    and on most platforms can be used for opening files as well.
</ul>

<h4>
<a name="show"></a>
int fltk::NativeFileChooser::show() const<br>
</h4>
<ul>
    Opens the current file chooser on the screen. This method
    will block until the user has chosen something, or cancelled.
    <p>
    Return value:
    <ul type=disc>
        <li> 0 - user picked a file, filename() will have the result
        <li> 1 - user hit 'cancel'
        <li>-1 - failed; <a href="#errmsg">errmsg()</a> has reason
    </ul>
</ul>

<h4>
<a name="title"></a>
const char *fltk::NativeFileChooser::title() const<br>
void fltk::NativeFileChooser::title(const char*)
</h4>
<ul>
    Gets or sets the title of the file chooser's window.
    <p>
    The default title varies according to the platform, so you
    are advised to set the title explicitly.
</ul>

<h4><a name="type"></a>
int fltk::NativeFileChooser::type() const<br>
fltk::NativeFileChooser::type(int)
</h4>
<ul>
    Gets or sets the current type of browser. Possible choices are:
    <p>
    <center><table cellpadding=3>
        <tr>
	  <td BGCOLOR=#8888cc align=left>Flag</td>
	  <td BGCOLOR=#8888cc>Description</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_FILE</td>
	  <td BGCOLOR=#dddddd>Browse for a single file</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_DIRECTORY</td>
	  <td BGCOLOR=#dddddd>Browse for a single directory</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_MULTI_FILE</td>
	  <td BGCOLOR=#dddddd>Browse for multiple files</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_MULTI_DIRECTORY</td>
	  <td BGCOLOR=#dddddd>Browse for multiple directories (implementation varies)</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_SAVE_FILE</td>
	  <td BGCOLOR=#dddddd>Browse to save a single file</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_SAVE_DIRECTORY</td>
	  <td BGCOLOR=#dddddd>Browse for a directory, allowing creation</td>
        </tr>
    </table></center>
    <p>
    These may be changed in future versions of fltk::NativeFileChooser.
</ul>

<h3>Typical Usage</h3>
<ul>
    <pre>
#include &lt;fltk/NativeFileChooser.h&gt;
:
fltk::NativeFileChooser *chooser = <b>new fltk::NativeFileChooser</b>();
<b>chooser-&gt;type</b>(fltk::NativeFileChooser::BROWSE_FILE);   <i>// let user browse a single file</i>
<b>chooser-&gt;title</b>("Open a file");                           <i>// optional title</i>
<b>chooser-&gt;preset_file</b>("/var/tmp/somefile.txt");           <i>// optional filename preset</i>
<b>chooser-&gt;filter</b>("Text Files\t*.txt");                    <i>// optional filter</i>
switch ( <b>chooser-&gt;show</b>() ) {
    case -1:    // ERROR
	fprintf(stderr, "*** ERROR show() failed:%s\n", <b>chooser-&gt;errmsg</b>());
	break;
    case 1:     // CANCEL
	fprintf(stderr, "*** CANCEL\n");
	break;
    default:    // USER PICKED A FILE
        fprintf(stderr, "Filename was '%s'\n", <b>chooser-&gt;filename</b>());
	break;
}
<p><hr><p>
<b>// EXAMPLE 'SAVEAS' FILE BROWSER</b>
#include &lt;fltk/NativeFileChooser.h&gt;
:
fltk::NativeFileChooser *chooser = <b>new fltk::NativeFileChooser</b>();
<b>chooser-&gt;type</b>(fltk::NativeFileChooser::BROWSE_SAVE_FILE);   <i>// 'saveas' browser</i>
<b>chooser-&gt;title</b>("Save As..");                                  <i>// optional title for chooser window</i>
<b>chooser-&gt;directory</b>("/var/tmp");                               <i>// optional starting directory</i>
<b>chooser-&gt;preset_file</b>("untitled.txt");                         <i>// optional default filename</i>
<b>chooser-&gt;filter</b>("Text Files\t*.txt");                         <i>// optional filter</i>
switch ( <b>chooser-&gt;show</b>() ) {
    case -1:    // ERROR
	fprintf(stderr, "*** ERROR show() failed:%s\n", <b>chooser-&gt;errmsg</b>());
	break;
    case 1:     // CANCEL
	fprintf(stderr, "*** CANCEL\n");
	break;
    default:    // USER PICKED A FILE
        fprintf(stderr, "Filename was '%s'\n", <b>chooser-&gt;filename</b>());
	break;
}
    </pre>
</ul>

<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>

<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>

<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>

</body>
</html>
